﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MedicWave.Visualization3d
{
    public partial class SaveFileSettingsForm : Form
    {
        int m_MaxWidth;
        int m_MaxHeight;
        int m_MinWidht= 100;
        int m_MinHeight= 100;
        public SaveFileSettingsForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
            Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Close();
        }

        internal DialogResult ShowDialog()
        {
            txtBoxHeight.KeyPress += new KeyPressEventHandler(txtInt_KeyPress);
            txtBoxWitdh.KeyPress += new KeyPressEventHandler(txtInt_KeyPress);

            txtBoxHeight.Leave += new EventHandler(txtBoxHeight_Leave);
            txtBoxWitdh.Leave += new EventHandler(txtBoxWitdh_Leave);

            m_MaxHeight = SystemInformation.PrimaryMonitorSize.Height;
            m_MaxWidth = SystemInformation.PrimaryMonitorSize.Width;
            return base.ShowDialog();
        }

        void txtBoxWitdh_Leave(object sender, EventArgs e)
        {
            int value = int.Parse(txtBoxWitdh.Text);
            if (value > m_MaxWidth)
                txtBoxWitdh.Text = m_MaxWidth.ToString();
            else if (value < m_MinWidht)
                txtBoxWitdh.Text = m_MinWidht.ToString();
        }

        void txtBoxHeight_Leave(object sender, EventArgs e)
        {
            int value = int.Parse(txtBoxHeight.Text);
            if (value > m_MaxHeight)
                txtBoxHeight.Text = m_MaxHeight.ToString();
            else if (value < m_MinHeight)
                txtBoxHeight.Text = m_MinHeight.ToString();
        }

        public int GetWidth()
        {
            return int.Parse(txtBoxWitdh.Text);
        }

        public int GetHeight()
        {
            return int.Parse(txtBoxHeight.Text);
        }

        public bool GetPrinterColors()
        {
            return checkBoxPrinterColors.Checked;
        }

        void txtInt_KeyPress(object sender, KeyPressEventArgs e)
        {
            string keyInput = e.KeyChar.ToString();
            System.Globalization.NumberFormatInfo numberFormatInfo = System.Globalization.CultureInfo.CurrentCulture.NumberFormat;
            string decimalSeparator = numberFormatInfo.NumberDecimalSeparator;
            string groupSeparator = numberFormatInfo.NumberGroupSeparator;
            string negativeSign = numberFormatInfo.NegativeSign;

            if (Char.IsDigit(e.KeyChar))
            {
                base.OnKeyPress(e);
                e.Handled = false;
            }
            else if (e.KeyChar == '\b')
            {
                base.OnKeyPress(e);
                e.Handled = false;
            }
            else if ((ModifierKeys & (Keys.Control | Keys.Alt)) != 0)
            {
                base.OnKeyPress(e);
                e.Handled = false;
            }
            else
            {
                // Consume this invalid key and beep
                e.Handled = true;
                //MessageBeep();
            }
        }
    }
}
